import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
// 路由规则
const routes = [
  {
    path: '/',
    // component: App,
    children: [
      { path: '', redirect: '/home' },
      {
        path: '/home',
        name: 'Home',
        component: () => import('@/views/home/index.vue'),
        meta: { title: 'MES数智生产', keepAlive: true }
      },
      // 排行
      {
        path: '/visitingRank',
        name: 'visitingRank',
        component: () => import('@/views/ranking/visitingRank.vue'),
        meta: { title: '拜访排行' }
      },
      {
        path: '/businessRank',
        name: 'businessRank',
        component: () => import('@/views/ranking/businessRank.vue'),
        meta: { title: '商机排行' }
      },
      {
        path: '/followUpRank',
        name: 'followUpRank',
        component: () => import('@/views/ranking/followUpRank.vue'),
        meta: { title: '跟进排行' }
      },
      {
        path: '/quotationRank',
        name: 'quotationRank',
        component: () => import('@/views/ranking/quotationRank.vue'),
        meta: { title: '报价排行' }
      },
      {
        path: '/losingRank',
        name: 'losingRank',
        component: () => import('@/views/ranking/losingRank.vue'),
        meta: { title: '流水排行'}
      },
      {
        path: '/tradeRank',
        name: 'tradeRank',
        component: () => import('@/views/ranking/tradeRank.vue'),
        meta: { title: '成单排行' }
      },
      {
        path: '/demand',
        name: 'demand',
        component: () => import('@/views/demand/index.vue'),
        meta: { title: '需求', keepAlive: true }
      },
      {
        path: '/addVisiting',
        name: 'addVisiting',
        component: () => import('@/views/businessOpportunity/addVisiting.vue'),
        meta: { title: '新增拜访' }
      },
      {
        path: '/addBusiness',
        name: 'addBusiness',
        component: () => import('@/views/businessOpportunity/addBusiness.vue'),
        meta: { title: '新增商机' }
      },
      {
        path: '/addQuote',
        name: 'addQuote',
        component: () => import('@/views/businessOpportunity/addQuote.vue'),
        meta: { title: '新增报价' }
      },
      {
        path: '/addTrade',
        name: 'addTrade',
        component: () => import('@/views/businessOpportunity/addTrade.vue'),
        meta: { title: '商机成交' }
      },
      {
        path: '/addLosing',
        name: 'addLosing',
        component: () => import('@/views/businessOpportunity/addLosing.vue'),
        meta: { title: '商机流失' }
      },
      {
        path: '/addFollowUp',
        name: 'addFollowUp',
        component: () => import('@/views/businessOpportunity/addFollowUp.vue'),
        meta: { title: '新建跟进' }
      },
      {
        path: '/quotation',
        name: 'quotation',
        component: () => import('@/views/businessOpportunity/quotation.vue'),
        meta: { title: '报价信息' }
      },
      {
        path: '/quotationDetail',
        name: 'quotationDetail',
        component: () => import('@/views/businessOpportunity/quotation.detail.vue'),
        meta: { title: '完整报价单' }
      },
      {
        path: '/product',
        name: 'product',
        component: () => import('@/views/product/index.vue'),
        meta: { title: '生产' }
      },
      {
        path: '/addCustomer',
        name: 'addCustomer',
        component: () => import('@/views/customer/addCustomer.vue'),
        meta: { title: '新建客户' }
      },
      {
        path: '/user',
        name: 'user',
        component: () => import('@/views/user/index.vue'),
        meta: { title: '我的' }
      },
      {
        path: '/consumeInfo',
        name: 'consumeInfo',
        component: () => import('@/views/consumeTrace/consumeInfo.vue'),
        meta: { title: '耗材详情' }
      },
      {
        path: '/addTrace',
        name: 'addTrace',
        component: () => import('@/views/consumeTrace/addTrace.vue'),
        meta: { title: '新增追溯记录' }
      },
      {
        path: '/login',
        name: 'login',
        component: () => import('@/views/login/index.vue'),
        meta: { title: '登录' }
      },
      {
        path: '/systemMaintenance',
        name: 'systemMaintenance',
        component: () => import('@/views/login/systemMaintenance.vue'),
        meta: { title: 'MES数智生产' }
      },
      {
        path: '/agreeMent',
        name: 'agreeMent',
        component: () => import('@/views/login/agreeMent.vue'),
        meta: { title: '注意事项' }
      },
      // 扩展内容
      {
        path: '/jsApi',
        name: 'jsApi',
        component: () => import('@/views/jsApi.vue'),
        meta: { title: 'jsApi' }
      }
      // {
      //   // vue-router@4的变化，舍弃*通配符
      //   // 官方文档：https://next.router.vuejs.org/zh/guide/migration/index.html#%E5%88%A0%E9%99%A4%E4%BA%86-%EF%BC%88%E6%98%9F%E6%A0%87%E6%88%96%E9%80%9A%E9%85%8D%E7%AC%A6%EF%BC%89%E8%B7%AF%E7%94%B1
      //   path: '/:pathMatch(.*)*',
      //   name: '404',
      //   component: () => import('@/views/404.vue')
      // }
    ]
  }
]

const router = createRouter({
  // vueRouter@3版本的mode改成了history，hash模式配置createWebHashHistory，history模式配置createWebHistory
  history: createWebHashHistory(),
  // history: createWebHistory(import.meta.env.VITE_USER_NODE_ENV == 'production' ? '/' : '/'),
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { left: 0, top: 0 }
    }
  },
  routes
})
export default router
